feat(inspect): Docker-compatible container inspect output (closes #36)#40
Merged
Conversation
container inspect (and inspect --type=container) returned the internal ContainerInfo shape instead of Docker's ContainerInspect shape. Add a ContainerInspect DTO + pure mapToContainerInspect mapper (mirroring the image-inspect pattern) and widen inspectContainers to return it. Output is now a single JSON array with Docker PascalCase keys (Id, Created, Name, State, Config, NetworkSettings, ...) and unescaped slashes. Fields Apple's Containerization runtime does not surface (HostConfig, Mounts, env, exit code, ...) are omitted rather than fabricated. --format and --size remain accepted-but-deferred. Closes #36
alex-mextner
added a commit
to alex-mextner/mocker
that referenced
this pull request
Jun 26, 2026
…ct commands
`inspect` -- and the dedicated `container inspect` / `image inspect` subcommands
-- declared `-f/--format` mirroring `docker inspect`, but parsed and then ignored
it: the full JSON array was always printed. Docker callers drive inspect with a
template and expect a bare scalar, e.g. dev stands and CI health gates:
docker inspect -f '{{.State.Running}}' <container> | grep -q true
Against the unevaluated flag that grep is a coin-flip on the substring "true"
appearing somewhere in the JSON dump.
Add a small Go text/template evaluator (`GoTemplate`) for the `{{ .Dotted.Path }}`
field-access subset real inspect callers use, and route every inspect entry point
through a shared `InspectFormat` helper that renders `--format` (one line per
record) and otherwise prints the JSON exactly as before. This also wires
`--format` into `container inspect` and `image inspect`, which previously accepted
the flag for Docker surface parity but never applied it.
Behavior:
- Paths resolve against the Docker-shaped inspect JSON from us#40 (`.State.Running`,
`.State.Status`, `.Id`, `.Name`, `.Config.Image`, `.NetworkSettings.IPAddress`,
...). Scalars render the Go way: bare `true`/`false`, integers without a decimal
point, strings verbatim; an unknown/null path and array/object leaves render empty.
- Substitution is a single left-to-right pass by match range, so a resolved value
that itself contains `{{...}}` is emitted verbatim and never re-triggers
substitution.
- `--format json` is treated as Docker's documented special value (emit the JSON),
not as a template.
- Any `{{...}}` block outside the supported field-access subset (`if`, `range`,
`json`, `index`, a bare `{{.}}`, ...) throws rather than passing through as
misleading literal text -- a silently-unevaluated template would feed false data
to the grep/jq pipelines these outputs drive.
Add GoTemplateTests covering the dev-stand health-gate paths, integer-vs-bool
scalars (incl. Pid 0 on a stopped container), whitespace, multi-token / repeated
tokens, no cross-token / re-entrant substitution, array-leaf-empty, the
JSONSerialization bool->NSNumber bridging path, and fail-loud rejection of
unsupported actions.
us
pushed a commit
that referenced
this pull request
Jun 27, 2026
…ct commands
`inspect` -- and the dedicated `container inspect` / `image inspect` subcommands
-- declared `-f/--format` mirroring `docker inspect`, but parsed and then ignored
it: the full JSON array was always printed. Docker callers drive inspect with a
template and expect a bare scalar, e.g. dev stands and CI health gates:
docker inspect -f '{{.State.Running}}' <container> | grep -q true
Against the unevaluated flag that grep is a coin-flip on the substring "true"
appearing somewhere in the JSON dump.
Add a small Go text/template evaluator (`GoTemplate`) for the `{{ .Dotted.Path }}`
field-access subset real inspect callers use, and route every inspect entry point
through a shared `InspectFormat` helper that renders `--format` (one line per
record) and otherwise prints the JSON exactly as before. This also wires
`--format` into `container inspect` and `image inspect`, which previously accepted
the flag for Docker surface parity but never applied it.
Behavior:
- Paths resolve against the Docker-shaped inspect JSON from #40 (`.State.Running`,
`.State.Status`, `.Id`, `.Name`, `.Config.Image`, `.NetworkSettings.IPAddress`,
...). Scalars render the Go way: bare `true`/`false`, integers without a decimal
point, strings verbatim; an unknown/null path and array/object leaves render empty.
- Substitution is a single left-to-right pass by match range, so a resolved value
that itself contains `{{...}}` is emitted verbatim and never re-triggers
substitution.
- `--format json` is treated as Docker's documented special value (emit the JSON),
not as a template.
- Any `{{...}}` block outside the supported field-access subset (`if`, `range`,
`json`, `index`, a bare `{{.}}`, ...) throws rather than passing through as
misleading literal text -- a silently-unevaluated template would feed false data
to the grep/jq pipelines these outputs drive.
Add GoTemplateTests covering the dev-stand health-gate paths, integer-vs-bool
scalars (incl. Pid 0 on a stopped container), whitespace, multi-token / repeated
tokens, no cross-token / re-entrant substitution, array-leaf-empty, the
JSONSerialization bool->NSNumber bridging path, and fail-loud rejection of
unsupported actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Closes #36.
mocker container inspect <id>(andmocker inspect --type=container <id>) returned mocker's internalContainerInfoshape instead of Docker'sContainerInspectshape. This completes the follow-up that #37 scaffolded.Changes
ContainerInspectDTO + puremapToContainerInspectmapper (Sources/MockerKit/Models/ContainerInspect.swift), mirroring the existing image-inspect pattern: PascalCaseCodingKeys, optional fields omitted when absent.inspectContainerswidened to return[ContainerInspect](the Docker DTO) — exactly the widening refactor: split container inspect into dedicated subcommand #37 anticipated.container inspect,inspect --type=container, and theinspectauto path.Example output:
[ { "Id": "abc123def456", "Created": "2023-11-14T22:13:20.000Z", "Name": "/web", "Image": "nginx:latest", "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 4242 }, "Config": { "Image": "nginx:latest", "Cmd": ["nginx","-g","daemon","off;"], "Labels": { "com.example": "x" } }, "NetworkSettings": { "IPAddress": "192.168.64.3", "Ports": { "80/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "8080" } ] } } } ]Scope / honesty
Fields Apple's Containerization runtime does not surface (
HostConfig,Mounts,RestartCount, env, exit code, start/finish timestamps, …) are omitted rather than fabricated — same approach as image inspect.--format(Go templates) and--sizeremain accepted-but-deferred; they are out of scope for the shape fix #36 asks for.Tests
swift test: 202/202 pass. NewContainerInspectMappingTests(8 tests) cover the Docker shape:/-prefixed name,stopped→exitedmapping, ports map shape, RFC3339Createdstring, omitted-when-absent fields, and PascalCase JSON serialization.